home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / a_utils / _archvrs / unix / unzip51 / tops20 / tops20.c < prev   
C/C++ Source or Header  |  1992-10-20  |  5KB  |  208 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.   tops20.c
  4.  
  5.   TOPS20-specific routines for use with Info-ZIP's UnZip 5.1 and later.
  6.  
  7.   ---------------------------------------------------------------------------*/
  8.  
  9.  
  10. #include "unzip.h"
  11.  
  12.  
  13. /**********************/
  14. /* Function mapattr() */
  15. /**********************/
  16.  
  17. int mapattr()      /* just like Unix except no umask() */
  18. {
  19.     ulg  tmp = crec.external_file_attributes;
  20.  
  21.     switch (pInfo->hostnum) {
  22.         case UNIX_:
  23.         case VMS_:
  24.             pInfo->file_attr = (unsigned)(tmp >> 16);
  25.             break;
  26.         case AMIGA_:
  27.             tmp = (unsigned)(tmp>>1 & 7);   /* Amiga RWE bits */
  28.             pInfo->file_attr = (unsigned)(tmp<<6 | tmp<<3 | tmp);
  29.             break;
  30.         case FS_FAT_:   /* MSDOS half of attributes should always be correct */
  31.         case FS_HPFS_:
  32.         case FS_NTFS_:
  33.         case MAC_:
  34.         case ATARI_:
  35.         case TOPS20_:
  36.         default:
  37.             tmp = !(tmp & 1) << 1;   /* read-only bit --> write perms bits */
  38.             pInfo->file_attr = (unsigned)(0444 | tmp<<6 | tmp<<3 | tmp);
  39.             break;
  40. #if 0
  41.         case ATARI_:
  42.         case TOPS20_:
  43.         default:
  44.             pInfo->file_attr = 0666;
  45.             break;
  46. #endif
  47.     } /* end switch (host-OS-created-by) */
  48.  
  49.     return 0;
  50.  
  51. } /* end function mapattr() */
  52.  
  53.  
  54.  
  55.  
  56.  
  57. /**************************************/
  58. /* Function set_file_time_and_close() */
  59. /**************************************/
  60.  
  61. void set_file_time_and_close()
  62. {
  63. #   define JSYS_CLASS           0070000000000
  64. #   define FLD(val,mask)        (((unsigned)(val)*((mask)&(-(mask))))&(mask))
  65. #   define _DEFJS(name,class)   (FLD(class,JSYS_CLASS) | (monsym(name)&0777777))
  66. #   define IDTIM                _DEFJS("IDTIM%", 1)
  67. #   define SFTAD                _DEFJS("SFTAD%", 0)
  68. #   define YRBASE               1900
  69.     int ablock[5], tblock[2];
  70.     int yr, mo, dy, hh, mm, ss;
  71.     char temp[100];
  72.     unsigned tad;
  73.  
  74.  
  75.     if (cflag)    /* can't set time on stdout */
  76.         return;
  77.  
  78.     /* dissect the date */
  79.     yr = ((lrec.last_mod_file_date >> 9) & 0x7f) + (1980 - YRBASE);
  80.     mo = (lrec.last_mod_file_date >> 5) & 0x0f;
  81.     dy = lrec.last_mod_file_date & 0x1f;
  82.  
  83.     /* dissect the time */
  84.     hh = (lrec.last_mod_file_time >> 11) & 0x1f;
  85.     mm = (lrec.last_mod_file_time >> 5) & 0x3f;
  86.     ss = (lrec.last_mod_file_time & 0x1f) * 2;
  87.     
  88.     sprintf(temp, "%02d/%02d/%02d %02d:%02d:%02d", mo, dy, yr, hh, mm, ss);
  89.  
  90.     ablock[1] = (int)(temp - 1);
  91.     ablock[2] = 0;
  92.     if (!jsys(IDTIM, ablock)) {
  93.         fprintf(stderr, "error:  IDTIM failure for %s\n", filename);
  94.         close(outfd);
  95.         return;
  96.     }
  97.  
  98.     tad = ablock[2];
  99.     tblock[0] = tad;
  100.     tblock[1] = tad;
  101.     tblock[2] = -1;
  102.  
  103.     ablock[1] = fcntl(outfd, F_GETSYSFD, 0);   /* _uffd[outfd]->uf_ch; */
  104.     ablock[2] = (int) tblock;
  105.     ablock[3] = 3;
  106.     if (!jsys(SFTAD, ablock))
  107.         fprintf(stderr, "error:  can't set the time for %s\n", filename);
  108.  
  109.     close(outfd);
  110.  
  111. } /* end function set_file_time_and_close() */
  112.  
  113.  
  114.  
  115.  
  116.  
  117. /**********************/
  118. /*  Function upper()  */
  119. /**********************/
  120.  
  121. int upper(s)        /* returns s in uppercase */
  122.     char *s;        /* string to be uppercased */
  123. {
  124.     for (;  *s;  ++s)
  125.         *s = toupper(*s);
  126. }
  127.  
  128.  
  129.  
  130.  
  131.  
  132. /************************/
  133. /*  Function enquote()  */
  134. /************************/
  135.  
  136. int enquote(s)      /* calls dequote(s) to normalize string, then */
  137.     char *s;        /*  inserts ^Vs before otherwise illegal characters */
  138. {                   /*  in s, assuming that s is a TOPS-20 filename */
  139.     char d[100];
  140.     char *p, *q;
  141.     char c;
  142.  
  143.     if (s && *s) {
  144.         dequote(s);
  145.         p = s - 1;
  146.         q = d - 1;
  147.         while (c = *++p) {
  148.             if (!fnlegal(c))
  149.                 *++q = '\026';
  150.             *++q = c;
  151.         }
  152.         *++q = '\0';
  153.         strcpy(s, d);
  154.     }
  155.     return 0;
  156. }
  157.  
  158.  
  159.  
  160.  
  161.  
  162. /************************/
  163. /*  Function dequote()  */
  164. /************************/
  165.  
  166. int dequote(s)        /* returns s without ^Vs */
  167.     char *s;          /* string to be dequoted */
  168. {
  169.     char d[100];
  170.     char *p, *q;
  171.     int c;
  172.  
  173.     if (s && *s) {
  174.         p = s - 1;
  175.         q = d - 1;
  176.         while (c = *++p)
  177.             if (c != '\026')
  178.                 *++q = c;
  179.         *++q = '\0';
  180.         strcpy(s, d);
  181.     }
  182.     return 0;
  183. }
  184.  
  185.  
  186.  
  187.  
  188.  
  189. /************************/
  190. /*  Function fnlegal()  */
  191. /************************/
  192.  
  193. int fnlegal(c)         /* returns TRUE if c is a member of the */
  194.     char c;            /*  legal character set for filenames */
  195. {
  196.     char *q;
  197.     static char *legals = {"$%**-<>>AZ[[]]__az"};
  198.  
  199.     q = legals;
  200.     while (*q)
  201.         if (c < *q++)
  202.             break;
  203.         else if (c <= *q++)
  204.             return TRUE;
  205.  
  206.     return FALSE;
  207. }
  208.